package com.admin.business.venusOrganizePost;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 岗位信息表
 * @create: 2022-03-22 18:46:06
 **/
@Service("venusOrganizePost")
@Slf4j
public class VenusOrganizePostService{

    @Resource
    VenusOrganizePostDao venusOrganizePostDao;

    /**
     * 添加岗位信息表,获取post_id数据
     *
     * @param cdoRequest - post_id:
     *                   - post_name:名称
     *                   - org_dept_id:部门id
     *                   - post_code:部门编码
     *                   - post_num:编制人数
     *                   - post_pay_start:薪资区间开始
     *                   - post_pay_end:薪资区间结束
     *                   - post_demand:任职要求
     *                   - post_duty:岗位职责
     *                   - post_job_num:岗位人数（入职人数）
     *                   - post_state:0停止招聘，1开始招聘，2删除，3正常
     *                   - post_update_time:发布时间
     *                   - org_id:公司ID
     *                   - post_user_id:创建人id
     *                   - project_id:项目id
     *                   - post_education:学历
     *                   - post_nature:工作性质
     *                   - post_create_time:创建时间
     *                   - post_experience:经验
     *                   - post_role_id:角色id
     *                   - post_status:0停止招聘，1开始招聘
     *                   - post_recruitment_time:发布时间
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return addVenusOrganizePost(CDO cdoRequest) {
        venusOrganizePostDao.addVenusOrganizePost(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("post_id")) {
            cdoResult.set("post_id", cdoRequest.get("post_id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据post_id，更新岗位信息表数据
     *
     * @param cdoRequest - post_id:
     *                   - post_name:名称
     *                   - org_dept_id:部门id
     *                   - post_code:部门编码
     *                   - post_num:编制人数
     *                   - post_pay_start:薪资区间开始
     *                   - post_pay_end:薪资区间结束
     *                   - post_demand:任职要求
     *                   - post_duty:岗位职责
     *                   - post_job_num:岗位人数（入职人数）
     *                   - post_state:0停止招聘，1开始招聘，2删除，3正常
     *                   - post_update_time:发布时间
     *                   - org_id:公司ID
     *                   - post_user_id:创建人id
     *                   - project_id:项目id
     *                   - post_education:学历
     *                   - post_nature:工作性质
     *                   - post_create_time:创建时间
     *                   - post_experience:经验
     *                   - post_role_id:角色id
     *                   - post_status:0停止招聘，1开始招聘
     *                   - post_recruitment_time:发布时间
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return updateVenusOrganizePostById(CDO cdoRequest) {
        int affectedRows = venusOrganizePostDao.updateVenusOrganizePostById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据post_id，删除岗位信息表数据
     *
     * @param cdoRequest - post_id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusOrganizePostById(CDO cdoRequest){
        int affectedRows = venusOrganizePostDao.deleteVenusOrganizePostById(cdoRequest.getInteger("post_id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除岗位信息表数据
     *
     * @param cdoRequest - post_name:名称
     *                   - org_dept_id:部门id
     *                   - post_state:0停止招聘，1开始招聘，2删除，3正常
     *                   - org_id:公司ID
     *                   - post_user_id:创建人id
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusOrganizePost(CDO cdoRequest) {
        int affectedRows = venusOrganizePostDao.deleteVenusOrganizePost(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取岗位信息表数据
     *
     * @param cdoRequest - post_id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizePostById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrganizePostDao.getVenusOrganizePostById(cdoRequest.getInteger("post_id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取岗位信息表数据
     *
     * @param cdoRequest - post_id:
     *                   - post_name:名称
     *                   - org_dept_id:部门id
     *                   - post_state:0停止招聘，1开始招聘，2删除，3正常
     *                   - org_id:公司ID
     *                   - post_user_id:创建人id
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizePost(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrganizePostDao.getVenusOrganizePost(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取岗位信息表数据列表
     *
     * @param cdoRequest - post_name:名称
     *                   - org_dept_id:部门id
     *                   - post_state:0停止招聘，1开始招聘，2删除，3正常
     *                   - org_id:公司ID
     *                   - post_user_id:创建人id
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizePostList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrganizePostDao.getVenusOrganizePostList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOrganizePostDao.getVenusOrganizePostListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取岗位信息表数据列表
     *
     * @param cdoRequest - post_id:
     *                   - post_name:名称
     *                   - org_dept_id:部门id
     *                   - post_state:0停止招聘，1开始招聘，2删除，3正常
     *                   - org_id:公司ID
     *                   - post_user_id:创建人id
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizePostListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrganizePostDao.getVenusOrganizePostListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOrganizePostDao.getVenusOrganizePostListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
